#include "lvgl_hint_anim.h"
#include "lvgl_Project.h"


#if 0
#define lvgl_hint_anim_debug(format, ...) lvgl_project_debug("[hint-anim]- ",format,##__VA_ARGS__);
#else
#define lvgl_hint_anim_debug(format, ...) ;
#endif


void lvgl_hint_anim_in_cb(void* arc, lv_anim_value_t v)
{
    lv_obj_set_y(arc, v);
}

void lvgl_hint_anim_in_ready_cb(lv_anim_t* anim)
{

    lvgl_hint_anim_debug("anim in ready");


    lvgl_send_event(&lvgl_hint_data.cont_main, CZ_EVENT_ANIM_IN_READY, NULL);
}

void lvgl_hint_anim_in_start(int mode, int time)
{
#if LVGL_ANIM_SWITCH



    lv_anim_path_init(&lvgl_hint_data.anim_path_in);
    lv_anim_path_set_cb(&lvgl_hint_data.anim_path_in, lv_anim_path_ease_out);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）

    lv_anim_init(&lvgl_hint_data.anim_in);


    lv_anim_set_exec_cb(&lvgl_hint_data.anim_in, lvgl_hint_anim_in_cb);
    lv_anim_set_ready_cb(&lvgl_hint_data.anim_in, lvgl_hint_anim_in_ready_cb);
    lv_anim_set_values(&lvgl_hint_data.anim_in, lv_obj_get_y(lvgl_hint_data.cont_main), lv_obj_get_height(lv_scr_act())-50);
    lv_anim_set_time(&lvgl_hint_data.anim_in, 200);
    lv_anim_set_var(&lvgl_hint_data.anim_in, lvgl_hint_data.cont_main);

    lv_anim_set_path(&lvgl_hint_data.anim_in, &lvgl_hint_data.anim_path_in);
    lv_anim_start(&lvgl_hint_data.anim_in);

#else


    lvgl_hint_anim_in_ready_cb(NULL);

#endif

}


void lvgl_hint_anim_out_cb(void* arc, lv_anim_value_t v)
{
    lv_obj_set_y(arc, v);
}
void lvgl_hint_anim_out_ready_cb(lv_anim_t* anim)
{

    lvgl_hint_anim_debug("anim out ready");


    lvgl_send_event(&lvgl_hint_data.cont_main, CZ_EVENT_ANIM_OUT_READY, NULL);
    lvgl_hint_close();

}

void lvgl_hint_anim_out_start(int mode, int time)
{

    lvgl_group_remove_obj(&lvgl_hint_data.cont_main);

#if LVGL_ANIM_SWITCH


    lv_anim_path_init(&lvgl_hint_data.anim_path_out);
    lv_anim_path_set_cb(&lvgl_hint_data.anim_path_out, lv_anim_path_ease_out);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）


    lv_anim_init(&lvgl_hint_data.anim_out);


    lv_anim_set_exec_cb(&lvgl_hint_data.anim_out, lvgl_hint_anim_out_cb);
    lv_anim_set_ready_cb(&lvgl_hint_data.anim_out, lvgl_hint_anim_out_ready_cb);
    lv_anim_set_values(&lvgl_hint_data.anim_out, lv_obj_get_y(lvgl_hint_data.cont_main), lv_obj_get_height(lv_scr_act()));
    lv_anim_set_time(&lvgl_hint_data.anim_out, 200);
    lv_anim_set_var(&lvgl_hint_data.anim_out, lvgl_hint_data.cont_main);

    lv_anim_set_path(&lvgl_hint_data.anim_out, &lvgl_hint_data.anim_path_out);
    lv_anim_start(&lvgl_hint_data.anim_out);

#else


    lvgl_hint_anim_out_ready_cb(NULL);

#endif

}
